﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.Configuration;

namespace MiniBug.Mail
{
    public sealed class MailSenderConfiguration
    {
        public MailSenderConfiguration()
        {
            try
            {
                smtpServer = GetSmtpServer();
                mailAdrressFrom = GetMailAddressFrom();
                smtpUser = GetSmtpUser();
                smtpPassword = GetSmtpPassword();
                smtpEnabledSSL = GetEnabledSsl();
                smtpPort = GetSmtpPort();
            }
            catch (Exception)
            {                
                throw;
            }            
        }

        public static MailSenderConfiguration GetMailSenderConfiguration()
        {
            return new MailSenderConfiguration();
        }

        private int GetSmtpPort()
        {
            int port;
            int.TryParse(ConfigurationManager.AppSettings["SmtpPort"], out port);
            return port;
        }

        private bool GetEnabledSsl()
        {
            bool ssl;
            bool.TryParse(ConfigurationManager.AppSettings["EnabledSsl"], out ssl);
            return ssl;
        }

        private string GetSmtpPassword()
        {
             return ConfigurationManager.AppSettings["SmtpPassword"].ToString();
        }

        private string GetSmtpUser()
        {
            return ConfigurationManager.AppSettings["SmtpUser"].ToString();
        }

        private string GetMailAddressFrom()
        {
            return ConfigurationManager.AppSettings["MailAddressFrom"].ToString();
        }

        private string GetSmtpServer()
        {
            return ConfigurationManager.AppSettings["SmtpServer"].ToString();
        }

        private int smtpPort;

        public int SmtpPort
        {
            get { return smtpPort; }
            set { smtpPort = value; }
        }

        private string mailAdrressFrom;

        public string MailAdrressFrom
        {
            get { return mailAdrressFrom; }
            set { mailAdrressFrom = value; }
        }
        private string smtpServer;

        public string SmtpServer
        {
            get { return smtpServer; }
            set { smtpServer = value; }
        }
        private string smtpPassword;

        public string SmtpPassword
        {
            get { return smtpPassword; }
            set { smtpPassword = value; }
        }
        private string smtpUser;

        public string SmtpUser
        {
            get { return smtpUser; }
            set { smtpUser = value; }
        }
        private bool smtpEnabledSSL;

        public bool SmtpEnabledSSL
        {
            get { return smtpEnabledSSL; }
            set { smtpEnabledSSL = value; }
        }
    }
}